package com.bwie.controller;

import com.bwie.pojo.TbActive;
import com.bwie.service.TbActiveService;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @description :
 * @Author QiHainan
 * @Create 2025/7/2 20:07
 * @Version 1.0
 */
@RestController
@RequestMapping("/win/index")
public class IndexController {
    @Autowired
    TbActiveService tbActiveService;
    @Autowired
    RedissonClient redissonClient;

    /**
     * 获取活动抽奖分页列表
     * @param pageInfoVo
     * @return
     */
    @PostMapping("/getActiveList")
    public R getActiveList(@RequestBody PageInfoVo pageInfoVo){
        return tbActiveService.getActiveList(pageInfoVo);
    }

    /**
     * 添加活动
     * @param tbActive
     * @return
     */
    @PostMapping("/addActive")
    public R addActive(@RequestBody @Validated TbActive tbActive){
        return tbActiveService.addActive(tbActive);
    }

    /**
     * 用户免费参加抽奖活动
     * @param activeId
     * @return
     */
    @PostMapping("/joinActive/{activeId}")
    public R joinActive(@PathVariable("activeId") Integer activeId){
        return tbActiveService.joinActive(activeId);
    }

    /**
     * 用户积分抽奖活动
     * @param activeId
     * @return
     */
    @PostMapping("/joinActiveByScore/{activeId}")
    public R joinActiveByScore(@PathVariable("activeId") Integer activeId){
        return tbActiveService.joinActiveByScore(activeId);
    }

    /**
     * 抽奖记录列表
     * @return
     */
    @PostMapping("/getJoinRecord")
    public R getJoinRecord(@RequestBody PageInfoVo pageInfoVo){
        return tbActiveService.getJoinRecord(pageInfoVo);
    }


    @PostMapping("/getTestRedis")
    public R getTestRedis(){
        RLock rLock = redissonClient.getLock("hahaha");
        rLock.lock();
        rLock.unlock();

        return R.ok();
    }

    /**
     * 根据活动ID获取活动信息
     * @param activeId
     * @return
     */
    @PostMapping("/getActiveById/{activeId}")
    public R getActiveById(@PathVariable("activeId") Integer activeId){
        return tbActiveService.getActiveById(activeId);
    }
}
